home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / findfi1a / tree2.frm (.txt) < prev   
Encoding:
Visual Basic Form  |  1999-10-12  |  11.4 KB  |  317 lines

  1. VERSION 5.00
  2. Object = "{6B7E6392-850A-101B-AFC0-4210102A8DA7}#1.3#0"; "COMCTL32.OCX"
  3. Begin VB.Form Form2 
  4.    Caption         =   "Exploring"
  5.    ClientHeight    =   6555
  6.    ClientLeft      =   60
  7.    ClientTop       =   345
  8.    ClientWidth     =   7875
  9.    LinkTopic       =   "Form2"
  10.    ScaleHeight     =   6555
  11.    ScaleWidth      =   7875
  12.    StartUpPosition =   3  'Windows Default
  13.    Begin VB.PictureBox splitter 
  14.       Height          =   6390
  15.       Left            =   3225
  16.       MousePointer    =   9  'Size W E
  17.       ScaleHeight     =   6330
  18.       ScaleWidth      =   270
  19.       TabIndex        =   3
  20.       Top             =   750
  21.       Width           =   330
  22.    End
  23.    Begin VB.TextBox Txtpath 
  24.       Height          =   345
  25.       Left            =   990
  26.       TabIndex        =   2
  27.       Top             =   0
  28.       Width           =   9750
  29.    End
  30.    Begin ComctlLib.ListView ListView1 
  31.       Height          =   6420
  32.       Left            =   3600
  33.       TabIndex        =   1
  34.       Top             =   720
  35.       Width           =   8445
  36.       _ExtentX        =   14896
  37.       _ExtentY        =   11324
  38.       View            =   3
  39.       LabelWrap       =   -1  'True
  40.       HideSelection   =   -1  'True
  41.       _Version        =   327682
  42.       ForeColor       =   -2147483640
  43.       BackColor       =   -2147483643
  44.       BorderStyle     =   1
  45.       Appearance      =   1
  46.       NumItems        =   0
  47.    End
  48.    Begin ComctlLib.TreeView TreeView1 
  49.       Height          =   6435
  50.       Left            =   30
  51.       TabIndex        =   0
  52.       Top             =   765
  53.       Width           =   3135
  54.       _ExtentX        =   5530
  55.       _ExtentY        =   11351
  56.       _Version        =   327682
  57.       Indentation     =   529
  58.       LineStyle       =   1
  59.       Style           =   7
  60.       ImageList       =   "ImageList1"
  61.       Appearance      =   1
  62.    End
  63.    Begin VB.Label Label1 
  64.       Caption         =   "Address:"
  65.       Height          =   315
  66.       Left            =   60
  67.       TabIndex        =   4
  68.       Top             =   30
  69.       Width           =   915
  70.    End
  71.    Begin ComctlLib.ImageList ImageList1 
  72.       Left            =   2790
  73.       Top             =   2985
  74.       _ExtentX        =   1005
  75.       _ExtentY        =   1005
  76.       BackColor       =   -2147483643
  77.       ImageWidth      =   16
  78.       ImageHeight     =   16
  79.       MaskColor       =   12632256
  80.       _Version        =   327682
  81.       BeginProperty Images {0713E8C2-850A-101B-AFC0-4210102A8DA7} 
  82.          NumListImages   =   2
  83.          BeginProperty ListImage1 {0713E8C3-850A-101B-AFC0-4210102A8DA7} 
  84.             Picture         =   "tree2.frx":0000
  85.             Key             =   ""
  86.          EndProperty
  87.          BeginProperty ListImage2 {0713E8C3-850A-101B-AFC0-4210102A8DA7} 
  88.             Picture         =   "tree2.frx":031A
  89.             Key             =   ""
  90.          EndProperty
  91.       EndProperty
  92.    End
  93. Attribute VB_Name = "Form2"
  94. Attribute VB_GlobalNameSpace = False
  95. Attribute VB_Creatable = False
  96. Attribute VB_PredeclaredId = True
  97. Attribute VB_Exposed = False
  98. Option Explicit
  99. 'variable to hold the width of the splitter bar
  100. Private Const SPLT_WDTH As Integer = 3
  101. Private ItemSelected As Integer
  102. 'variable to hold the last-sized position
  103. Private currSplitPosX As Long
  104. 'variable to hold the horizontal & vertical
  105. 'offsets of the 2 controls
  106. Dim CTRL_OFFSET As Integer
  107. 'variable to hold the Splitter bar colour
  108. Dim SPLT_COLOUR As Long
  109. Private Sub FilesSearch(drivepath As String, ext As String)
  110.     Dim XDir() As String
  111.     Dim tmpdir As String
  112.     Dim FFound As String
  113.     Dim DirCount As Integer
  114.     Dim X As Integer
  115.     Dim ls As ListItem
  116.     Dim ns As Node
  117.     Dim treechild As String
  118.     Dim treekey As String
  119.    'Initialises Variables
  120.     DirCount = 0
  121.     ReDim XDir(0) As String
  122.     XDir(DirCount) = ""
  123.     If Right(drivepath, 1) <> "\" Then
  124.         drivepath = drivepath & "\"
  125.     End If
  126.     DoEvents
  127.         tmpdir = Dir(drivepath, vbDirectory)
  128.         Do While tmpdir <> ""
  129.            If tmpdir <> "." And tmpdir <> ".." Then
  130.                If (GetAttr(drivepath & tmpdir) And vbDirectory) = vbDirectory Then
  131.                     treekey = drivepath & tmpdir
  132.                     Set ns = TreeView1.Nodes.Add(, , treekey, tmpdir, 1, 2)
  133.                     XDir(DirCount) = drivepath & tmpdir & "\"
  134.                     DirCount = DirCount + 1
  135.                     ReDim Preserve XDir(DirCount) As String
  136.                 End If
  137.             End If
  138.             tmpdir = Dir
  139.          Loop
  140.          
  141.         'Searches for the files given by extension Ext
  142.         FFound = Dir(drivepath & ext)
  143.         Do Until FFound = ""
  144.             Set ls = ListView1.ListItems.Add(1, "main" & FFound, FFound)
  145.             ls.SubItems(1) = drivepath
  146.             ls.SubItems(2) = Format(FileLen(drivepath & FFound), "###,###") & " Bytes"
  147.             ls.SubItems(3) = FileDateTime(drivepath & FFound)
  148.             FFound = Dir
  149.         Loop
  150.         
  151.         'Recursive searches through all sub directories
  152.         For X = 0 To (UBound(XDir) - 1)
  153.              treechild = Left(XDir(X), Len(XDir(X)) - 1)
  154.             FilesSearch1 XDir(X), ext, treechild
  155.         Next X
  156. End Sub
  157. Private Sub Form_Load()
  158. Dim path As String
  159.     'set the startup variables
  160.     CTRL_OFFSET = txtPath.Height
  161.     SPLT_COLOUR = &H808080
  162.     'set the current splitter bar position to an arbitrary value that
  163.     '     will always be outside
  164.     'the possible range. This allows us to check for movement of the
  165.     '     spltter bar in subsequent
  166.     'mousexxx subs.
  167.     currSplitPosX = &H7FFFFFFF
  168.     'ADD THE COLUMN HEADERS FOR THE LISTVIEW
  169.     ListView1.ColumnHeaders.Add 1, "name", "Name"
  170.     ListView1.ColumnHeaders.Add 2, "infolder", "In Folder"
  171.     ListView1.ColumnHeaders.Add 3, "size", "Size"
  172.     ListView1.ColumnHeaders.Add 4, "date", "Date Modified"
  173. End Sub
  174. Private Sub FilesSearch1(drivepath As String, ext As String, treekeys As String)
  175.     Dim XDir() As String
  176.     Dim tmpdir As String
  177.     Dim FFound As String
  178.     Dim DirCount As Integer
  179.     Dim X As Integer
  180.     Dim ls As ListItem
  181.     Dim ns As Node
  182.     Dim treechild As String
  183.     Dim treekey As String
  184.     'Initialises Variables
  185.     DirCount = 0
  186.     ReDim XDir(0) As String
  187.     XDir(DirCount) = ""
  188.     If Right(drivepath, 1) <> "\" Then
  189.         drivepath = drivepath & "\"
  190.       
  191.     End If
  192.     DoEvents
  193.         tmpdir = Dir(drivepath, vbDirectory)
  194.         Do While tmpdir <> ""
  195.            If tmpdir <> "." And tmpdir <> ".." Then
  196.                If (GetAttr(drivepath & tmpdir) And vbDirectory) = vbDirectory Then
  197.                    treekey = drivepath & tmpdir
  198.                    'SET THE KEY SAME AS THE PATH SO AS TO GET CORRECT VALUES INTO LISTVIEW WHEN THE TREEVIEW IS CLICKED
  199.                    Set ns = TreeView1.Nodes.Add(treekeys, tvwChild, treekey, tmpdir, 1, 2)
  200.                    XDir(DirCount) = drivepath & tmpdir & "\"
  201.                     DirCount = DirCount + 1
  202.                     ReDim Preserve XDir(DirCount) As String
  203.                 End If
  204.             End If
  205.             tmpdir = Dir
  206.         Loop
  207.         
  208.         'Recursive searches through all sub directories
  209.         For X = 0 To (UBound(XDir) - 1)
  210.             treechild = Left(XDir(X), Len(XDir(X)) - 1)
  211.             FilesSearch1 XDir(X), ext, treechild
  212.         Next X
  213. End Sub
  214. Private Sub Form_Resize()
  215.  Dim x1 As Integer, aErr$
  216.     Dim x2 As Integer
  217.     Dim height1 As Integer
  218.     Dim width1 As Integer
  219.     Dim width2 As Integer
  220.     'set the height of the controls
  221.     txtPath.Width = Me.Width + Label1.Width
  222.     height1 = ScaleHeight + txtPath.Height - (CTRL_OFFSET * 2)
  223.     width1 = TreeView1.Width
  224.     x1 = 10 + 2
  225.     x2 = x1 + width1 + SPLT_WDTH - 1 + 5
  226.     width2 = ScaleWidth - x2 - 10
  227.     'move the left list
  228.     If Me.WindowState <> 1 Then
  229.     TreeView1.Move x1 - 1, CTRL_OFFSET, width1, height1
  230.     'move the right textbox
  231.     ListView1.Move x2, CTRL_OFFSET, width2 + 1, height1
  232.     'move the splitter bar
  233.     splitter.Move x1 + TreeView1.Width - 1, CTRL_OFFSET, SPLT_WDTH, height1
  234.     End If
  235. End Sub
  236. Private Sub txtPath_KeyDown(KeyCode As Integer, Shift As Integer)
  237. 'IF ENTER KEY IS PRESSED
  238. If KeyCode = 13 Then
  239.     FilesSearch txtPath, "*.*"
  240.     Me.Caption = "Exploring" & txtPath
  241. End If
  242. End Sub
  243. Private Sub TreeView1_DblClick()
  244. Dim drivepath As String
  245. Dim tmpdir$, ls As ListItem
  246. ListView1.ListItems.Clear
  247. drivepath = TreeView1.SelectedItem.Key & "\"
  248. txtPath = TreeView1.SelectedItem.Key
  249. Me.Caption = "Exploring" & txtPath
  250.         tmpdir = Dir(drivepath, vbDirectory)
  251.         Do While tmpdir <> ""
  252.           
  253.             If tmpdir <> "." And tmpdir <> ".." Then
  254.                If (GetAttr(drivepath & tmpdir) And vbDirectory) <> vbDirectory Then
  255.                     Set ls = ListView1.ListItems.Add(1, tmpdir, tmpdir)
  256.                     ls.SubItems(1) = drivepath
  257.                     ls.SubItems(2) = Format(FileLen(drivepath & tmpdir), "###,###") & " Bytes"
  258.                     ls.SubItems(3) = FileDateTime(drivepath & tmpdir)
  259.                 End If
  260.             End If
  261.             tmpdir = Dir
  262.             
  263.         Loop
  264. End Sub
  265. Private Sub splitter_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
  266.     If Button = vbLeftButton Then
  267.         'change the splitter colour
  268.         splitter.BackColor = SPLT_COLOUR
  269.         'set the current position to x
  270.         currSplitPosX = CLng(X)
  271.     Else
  272.         'not the left button, so... if the current position <> defa
  273.         '     ult, cause a mouseup
  274.         If currSplitPosX <> &H7FFFFFFF Then splitter_MouseUp Button, Shift, X, Y
  275.         'set the current position to the default value
  276.         currSplitPosX = &H7FFFFFFF
  277.     End If
  278. End Sub
  279. Private Sub splitter_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
  280.     'if the splitter has been moved...
  281.    If currSplitPosX& <> &H7FFFFFFF Then
  282.         
  283.         'if the current position <> default, reposition the splitte
  284.         '     r and set this as the current value
  285.         If CLng(X) <> currSplitPosX Then
  286.             splitter.Move splitter.Left + X, CTRL_OFFSET, SPLT_WDTH, ScaleHeight - (CTRL_OFFSET * 2)
  287.             currSplitPosX = CLng(X)
  288.         End If
  289.     End If
  290.   End Sub
  291. Private Sub splitter_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
  292.     'if the splitter has been moved...
  293.     If currSplitPosX <> &H7FFFFFFF Then
  294.         'if the current position <> the last position do a final mo
  295.         '     ve of the splitter
  296.         If CLng(X) <> currSplitPosX Then
  297.             splitter.Move splitter.Left + X, CTRL_OFFSET, SPLT_WDTH, ScaleHeight - (CTRL_OFFSET * 2)
  298.         End If
  299.         'call this the default position
  300.         currSplitPosX = &H7FFFFFFF
  301.         'restore the normal splitter colour
  302.         splitter.BackColor = &H8000000F
  303.         'and check for valid sizings. Either enforce the default minimum
  304.         '     &
  305.         'maximum widths for the left list, or, if within range, set the w
  306.         '     idth.
  307.         If splitter.Left > 60 And splitter.Left < (ScaleWidth - 60) Then
  308.             TreeView1.Width = splitter.Left - TreeView1.Left 'the pane is within range
  309.         ElseIf splitter.Left < 60 Then 'the pane is too small
  310.             TreeView1.Width = 60
  311.         Else: TreeView1.Width = ScaleWidth - 60 'the pane is too wide
  312.         End If
  313.        'reposition both lists, and the splitter bar
  314.         Form_Resize
  315.     End If
  316.     End Sub
  317.